package chuangyi.com.org.ViewModel;

import android.app.Activity;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.content.Context;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.databinding.BaseObservable;
import android.databinding.Bindable;
import android.databinding.DataBindingUtil;
import android.databinding.tool.DataBindingBuilder;
import android.hardware.SensorManager;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;

import java.math.BigDecimal;
import java.util.Date;

import chuangyi.com.org.DOMIHome.BR;
import chuangyi.com.org.DOMIHome.Fragments.CommonFragment;
import chuangyi.com.org.DOMIHome.HomeActivity;
import chuangyi.com.org.DOMIHome.R;
import chuangyi.com.org.DOMIHome.SaveContent;
import chuangyi.com.org.DOMIHome.Utils.WebApi;
import chuangyi.com.org.DOMIHome.adapter.BindingListItem;
//import fm.jiecao.jcvideoplayer_lib.JCVideoPlayer;
//import fm.jiecao.jcvideoplayer_lib.JCVideoPlayerStandard;
//import io.vov.vitamio.MediaPlayer;
//import io.vov.vitamio.Vitamio;
//import io.vov.vitamio.widget.MediaController;
//import io.vov.vitamio.widget.VideoView;

/**
 * Created by zxh on 16/11/1.
 */

public class VideoItem extends BindingListItem {
    private int videoid;
    private String videoname;
    private String videodesc;
    private String cover;
    private String videopath;
    private String videotype;
    private double price;
    private int freeflag;
    private int uid;
    private String speaker;
    private Date uploadate;
    private String notepath;
//    private VideoView videoView;

    private int otherVisibility;
    // 视频详情页的根容器
    private RelativeLayout fragmentRoot;
//
//    public VideoView getVideoView() {
//        return videoView;
//    }

    public VideoItem(Context context, int layout) {
        super(context, layout);
    }

    @Bindable
    public int getVideoid() {
        return videoid;
    }

    public void setVideoid(int videoid) {
        this.videoid = videoid;
    }

    @Bindable
    public String getVideoname() {
        return videoname;
    }

    public void setVideoname(String videoname) {
        this.videoname = videoname;
        notifyPropertyChanged(BR.videoname);
    }

    @Bindable
    public String getVideodesc() {
        return videodesc;
    }

    public void setVideodesc(String videodesc) {
        this.videodesc = videodesc;
        notifyPropertyChanged(BR.videodesc);
    }

    @Bindable
    public String getCover() {
        return cover;
    }

    public void setCover(String cover) {
        this.cover = cover;
        notifyPropertyChanged(BR.cover);
    }

    @Bindable
    public String getVideopath() {
        return videopath;
    }

    public void setVideopath(String videopath) {
        this.videopath = videopath;
    }

    @Bindable
    public String getVideotype() {
        return videotype;
    }

    public void setVideotype(String videotype) {
        this.videotype = videotype;
    }

    @Bindable
    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
        notifyPropertyChanged(BR.cover);
    }

    @Bindable
    public int getFreeflag() {
        return freeflag;
    }

    public void setFreeflag(int freeflag) {
        this.freeflag = freeflag;
    }

    @Bindable
    public int getUid() {
        return uid;
    }

    public void setUid(int uid) {
        this.uid = uid;
    }

    @Bindable
    public String getSpeaker() {
        return speaker;
    }

    public void setSpeaker(String speaker) {
        this.speaker = speaker;
        notifyPropertyChanged(BR.speaker);
    }

    @Bindable
    public Date getUploadate() {
        return uploadate;
    }

    public void setUploadate(Date uploadate) {
        this.uploadate = uploadate;
        notifyPropertyChanged(BR.uploadate);
    }

    @Bindable
    public String getNotepath() {
        return notepath;
    }

    public void setNotepath(String notepath) {
        this.notepath = notepath;
        notifyPropertyChanged(BR.notepath);
    }

    @Bindable
    public int getOtherVisibility() {
        return otherVisibility;
    }

    public void setOtherVisibility(int otherVisibility) {
        this.otherVisibility = otherVisibility;
        notifyPropertyChanged(BR.otherVisibility);
    }

    /**
     * 点击视频项时的操作
     *
     * @param view
     */
    public void onItemClick(View view) {
        final Activity activity = (Activity) view.getContext();
        this.setOtherVisibility(View.VISIBLE);

        final CommonFragment fragment = HomeActivity.openVideoDetail(getContext(), videoid, null);
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    VideoDetail current = WebApi.getVideoDetail(getContext(), getVideoid());
                    current.setContext(getContext());
                    fragment.setDataModel(current);
                } catch (Exception ex) {
                    showToast(ex.getMessage());
                }
            }
        }).start();
    }

    /**
     * 点击用户头像时打开个人主页
     *
     * @param view
     */
    public void onClickAvatar(View view) {
        HomeActivity.showPersonalCentral(getContext(), getUid());
    }
}
